// pages/myfix/myfix.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    finish:[],
    unfinish:[],
    isClick1:true,
    isClick2:true,

  },

  toHome:function(){
    wx.switchTab({
      url: '../home/home',
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  dels:function(e){
    let item=e.currentTarget.dataset.num;
    let num=wx.getStorageSync('username');
    console.log(item)
    let that=this;
      wx.showModal({
        title: '提示',
        content: '是否要删除',
        success: function (res) {
          if (res.confirm) {//这里是点击了确定以后
            wx.request({
              url:'https://yali.geekwhite.cn:3000/fixdel', 
              // header: { 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' },
              header:{'Access-Control-Allow-Origin':'*'},
              header:{'Access-Control-Allow-Methods':'GET,POST'},
              data: {
                item,
                sno:num,
                type:"del"
               },
               method: 'post',
              success:(res)=>{
                console.log(res.data)
                res.data.map((item)=>{
                  if(item.lebal==0)
                    this.data.unfinish.push(item)
                 if(item.lebal==1)
                    this.data.finish.push(item)
                })
                that.setData({
                  unfinish:this.data.unfinish,
                  finish:this.data.finish
                })
              
              }
            })
          } else {//这里是点击了取消以后
            console.log('用户点击取消')
          } 
        }
      })

  },

click:function(e){
  let item=e.currentTarget.dataset.num;
  let click1= this.data.isClick1;
  let click2= this.data.isClick2;
  if(item==0){
    click1=true;
    click2=true
  }
  if(item==1){
    click1=true;
    click2=false;
  }
  if(item==2){
    click1=false;
    click2=true
  }
  this.setData({
      isClick1:click1,
      isClick2:click2
  })

},

  onLoad: function (options) {
  

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.setNavigationBarTitle({
      title: '我的报修',
    })
    let num=wx.getStorageSync('username');
   
    wx.request({
      url:'https://yali.geekwhite.cn:3000/fixdel', 
      // header: { 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' },
      header:{'Access-Control-Allow-Origin':'*'},
      header:{'Access-Control-Allow-Methods':'GET,POST'},
      data: {
        sno:num,
        type:"nodel"

       },
       method: 'post',
       success:res=> {
             console.log(res.data)
            res.data.map((item)=>{
              if(item.lebal==0)
                this.data.unfinish.push(item)
             if(item.lebal==1)
                this.data.finish.push(item)
            })
            this.setData({
              unfinish:this.data.unfinish,
              finish:this.data.finish
            })   
       },
    }) 
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})